//
//  EditMessagePerVC.m
//  LoveTrail
//
//  Created by giantumbrella on 15/6/11.
//  Copyright (c) 2015年 赵娟. All rights reserved.
//

#import "EditMessagePerVC.h"


@interface EditMessagePerVC ()<UITextFieldDelegate>{
    NSArray *dataArray;
    NSArray *babyArray;
    NSDictionary *param;
    NSString *tempValue;
}

@end

@implementation EditMessagePerVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleView: self.titleString];
    //添加东西
    [self addSubViews];
}

- (void)requestData {
    NSString *string = @"";
    NSMutableDictionary *modelDic = self.model.keyValues;
    if ([self.titleString isEqualToString:@"昵称"]) {
        string = @"nickName";
    } else if ([self.titleString isEqualToString:@"真实姓名"]) {
        string = @"realName";
    } else if ([self.titleString isEqualToString:@"手机号"]) {
        string = @"cellPhone";
    } else if ([self.titleString isEqualToString:@"邮箱"]) {
        string = @"email";
    } else if ([self.titleString isEqualToString:@"用户介绍"]) {
        string = @"introduction";
    } else if ([self.titleString isEqualToString:@"公司名称"]) {
        string = @"firmName";
    } else if ([self.titleString isEqualToString:@"有效证件号码"]) {
        string = @"identificationNumber";
    } else if ([self.titleString isEqualToString:@"网店地址链接"]) {
        string = @"storeAddressLink";
    } else if ([self.titleString isEqualToString:@"销售产品类别"]) {
        string = @"saleProductCategory";
    } else if ([self.titleString isEqualToString:@"付款账号/卡号"]) {
        string = @"payAccount";
    }

    [modelDic setValue:self.textField.text forKey:string];
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:[UserModel sharedInstance].userToken,@"token", nil];
    [dic setValuesForKeysWithDictionary:modelDic];
    [RequestData updateUserInfo:[UIUtil toJsonString:dic] withBlock:^(NSString *msg, NSError *error) {
        if (error) {
            if ([msg isEqualToString:@"9001"] || [msg isEqualToString:@"9002"]) {
                [UIUtil tokenOverdue:self msg:msg];
            } else {
                [[ESHUDView sharedInstance] showErrorMessage:msg==nil?@"提交失败":msg dismissBlock:nil];
            }
        } else {
            [[ESHUDView sharedInstance] showSuccessMessage:msg==nil?@"提交成功":msg dismissBlock:nil];
            if (_infoBlock) {
                _infoBlock (self.textField.text);
            }
            [self.navigationController popViewControllerAnimated:YES];
        }
    }];
}

#pragma mark 创建tableView
- (void)addSubViews {
    //右侧按钮
    UIBarButtonItem *rightButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStyleBordered target:self action:@selector(saveDataAndBack)];
    self.navigationItem.rightBarButtonItem = rightButtonItem;
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
    
    self.textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 15, SCREEN_WIDTH, 40)];
    self.textField.backgroundColor = [UIColor whiteColor];
    self.textField.layer.borderColor = [UIUtil colorWithHexString:@"#e3e3e3"].CGColor;
    self.textField.textColor = [UIUtil colorWithHexString:@"#9a9a9a"];
    self.textField.layer.borderWidth = 1;
    [self.view addSubview:self.textField];
    self.textField.delegate = self;
    self.textField.text = self.pathStringValue;
}


#pragma mark 保存 返回上
- (void)saveDataAndBack{
    [self requestData];
}


- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.textField endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
